﻿/********************************************************************************/
// <copyright file="Utility.js" company="Asia E-Business Solutions">
//     Copyright © 2012. All right reserved
// </copyright>
//
// <history>
//  <change who="Hieu Nguyen" date="20/12/2012 2:53:02 PM">Created</change>
// <history>
/********************************************************************************/
/**
* Create Namespace Object
**/
var Namespace = {
    Register: function(_Name) {
        var chk = false;
        var cob = "";
        var spc = _Name.split(".");
        for (var i = 0; i < spc.length; i++) {
            if (cob != "") { cob += "." }
            cob += spc[i];
            chk = this.Exists(cob);
            if (!chk) { this.Create(cob); }
        }
        if (chk) { throw "Namespace: " + _Name + " is already defined."; }
    },
    Create: function(_Src) {
        eval("window." + _Src + " = new Object(); ");
    },
    Exists: function(_Src) {
        eval("var NE = false;try{if(" + _Src + "){NE = true;}else{ NE = false;}} catch(err){}");
        return NE;
    }
}
/**
* Dump Object 
**/
var dump_js = function(variable, maxDeep) {
    var deep = 0;
    var maxDeep = maxDeep || 0;

    function fetch(object, parent) {
        var buffer = '';
        deep++;

        for (var i in object) {
            if (parent) {
                objectPath = parent + '.' + i;
            } else {
                objectPath = i;
            }

            buffer += objectPath + ' (' + typeof object[i] + ')';

            if (typeof object[i] == 'object') {
                buffer += "\n";
                if (deep < maxDeep) {
                    buffer += fetch(object[i], objectPath);
                }
            } else if (typeof object[i] == 'function') {
                buffer += "\n";
            } else if (typeof object[i] == 'string') {
                buffer += ': "' + object[i] + "\"\n";
            } else {
                buffer += ': ' + object[i] + "\n";
            }
        }

        deep--;
        return buffer;
    }

    if (typeof variable == 'object') {
        return fetch(variable);
    }

    return '(' + typeof variable + '): ' + variable + "-";
}

/**
*Load Dynamic Css
**/
function loadcssfile(filename) {
    var fileref = document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

function openWindow(website) {
    var winwidth = window.screen.availWidth;
    var winheight = window.screen.availHeight;
    var windowprops = 'width=' + winwidth + ',height=' + winheight + ',scrollbars=yes,status=yes,resizable=yes,'
    var left = 0;
    var top = 0;

    if (window.resizeTo && navigator.userAgent.indexOf("Opera") == -1) {

        var sizer = window.open("", "", "left=" + left + ",top=" + top + "," + windowprops);
        sizer.location = website;
    }
    else
        window.open(website, 'mywindow');

}